import java.io.IOException;


public class Sexpr {
	boolean isAtom;
	boolean isNIL;
	boolean isNumber;
	boolean isID;
	Sexpr car;
	Sexpr cdr;
	String Value;
	//int pcounter = 0;
	public static Sexpr NIL = new Sexpr("NIL");
	public static Sexpr T = new Sexpr("T");
	
	Sexpr(String value)
	{
		this.Value = value.toUpperCase();
		isAtom =true;
		isNumber = false;
		isID =false;
		//isNIL = this.Value.equals("NIL");
		if(this.Value.equals("NIL"))
			isNIL = true;
		else if(this.Value.equals("NULL"))
			isNIL = true;
	}
	Sexpr(Sexpr car, Sexpr cdr)
	{
		this.car = car;
		this.cdr = cdr;
		isAtom = false;
		isNumber = false;
		isNIL = false;
	}	
	public int sexprLength(Sexpr sexpr)
	{
		int n = 0;
		while(sexpr.isNIL != true)
		{
			if(sexpr.isAtom == true)
				return -1;
			else
			{
				sexpr = sexpr.cdr;
				n = n + 1;
				if(sexpr.car == null)
					break;
			}
		}
		return n;
	}
	public Sexpr cloneSexpr(Sexpr sexpr)
	{
		Sexpr ret = new Sexpr("NIL");
		ret.isAtom = false;
		ret.isID = false;
		ret.isNIL = false;
		ret.isNumber = false;
		if(sexpr.isAtom == false)
		{
			ret.car = cloneSexpr(sexpr.car);
			ret.cdr = cloneSexpr(sexpr.cdr);
			return ret;
		}
		else 
		{
			if(sexpr.isID == true)
			{
				ret.Value = sexpr.Value;
				ret.isAtom = true;
				ret.isID = true;
				ret.isNumber = false;
				ret.isNIL = false;
				return ret;
			}
			else if(sexpr.isNumber == true)
			{
				ret.Value = sexpr.Value;
				ret.isAtom = true;
				ret.isID = false;
				ret.isNIL = false;
				ret.isNumber = true;
				return ret;
			}
		}
		return ret;
		
	}
	public static void main(String[] args) throws Exception 
	{


	}
		
	

}
